package Secondpagh;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Switch;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.gyf.immersionbar.ImmersionBar;

import SHU.water2.R;
import SHU.water2.loginin;
import ThirdPagh.historyL;
import ThirdPagh.historypic;

import static SHU.water2.MainActivity.globalj;
import static SHU.water2.MainActivity.globals;

public class set extends AppCompatActivity implements View.OnClickListener {

    public SharedPreferences sharedPreferences;
    public SharedPreferences.Editor editor;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.set);
        ImmersionBar.with(this).statusBarColor(R.color.color).fitsSystemWindows(true).init();

        Button nick = findViewById(R.id.nickname);
        nick.setText("姓名： " + loginin.nickname);
        Button phone = findViewById(R.id.phone);
        phone.setText("手机号： " + loginin.phonenum);

        click();
        sharedPreferences = getSharedPreferences("soundAndJar", MODE_PRIVATE);
        editor = sharedPreferences.edit();
        globalj = sharedPreferences.getBoolean("statementJ",globalj);
        globals = sharedPreferences.getBoolean("statementS",globals);

        Switch mSwitchS = findViewById(R.id.switch1);
        Switch mSwitchJ = findViewById(R.id.switch2);
        if (globals == true)
            mSwitchS.setChecked(true);
        else mSwitchS.setChecked(false);
        if (globalj == true)
            mSwitchJ.setChecked(true);
        else mSwitchJ.setChecked(false);

        System.out.println(globalj);
    }

    private void click() {
        findViewById(R.id.nickname).setOnClickListener(this);
        findViewById(R.id.ret1).setOnClickListener(this);
        findViewById(R.id.switch1).setOnClickListener(this);
        findViewById(R.id.switch2).setOnClickListener(this);
        findViewById(R.id.historyLocation).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ret1:
                /*intent.setClass(getApplicationContext(), MainActivity.class);
                startActivity(intent);*/
                finish();
                break;
            case R.id.switch1:
                if (globals == true)
                    globals = false;
                else globals = true;
                break;
            case R.id.switch2:
                if (globalj == true)
                    globalj = false;
                else globalj = true;
                break;
            case R.id.historyLocation:
                Intent intent = new Intent();
                intent.setClass(getApplicationContext(), historyL.class);
                startActivity(intent);
                break;
        }
        editor.putBoolean("statementJ", globalj);
        editor.putBoolean("statementS", globals);
        editor.commit();
    }
}
